﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using Microsoft.SharePoint.Utilities;
using System.Windows.Forms;

namespace SPPoSh.Installer
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                string spSetupPath = SPUtility.GetGenericSetupPath(string.Empty);
                txtPath.Text = spSetupPath;
            }
            catch {
                btnInstall.Enabled = false;
            }
        }

        private void btnInstall_Click(object sender, EventArgs e)
        {
            System.IO.File.Copy("Registration/SPPoShCmdlets.xml", txtPath.Text + "CONFIG/POWERSHELL/Registration/SPPoShCmdlets.xml",true);
            System.IO.File.Copy("Help/SPPoSh.Cmdlets.dll-help.xml", txtPath.Text + "CONFIG/POWERSHELL/Help/SPPoSh.Cmdlets.dll-help.xml", true);
            try
            {
                System.IO.File.Copy("Assembly/SPPoSh.Cmdlets.dll", "C:\\Windows\\assembly\\SPPoSh.Cmdlets.dll", true);
            }
            catch {
                MessageBox.Show("Error copying {" + Application.StartupPath + "\\Assembly\\SPPoSh.Cmdlets.dll} to the Global Assembly Cache. Please perform this step manually.");
            }
        }
    }
}
